package com.edu.chongdian.viewmodels;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import java.util.List;


public class pageadapter extends PagerAdapter {
    private Context context;
    private List<Integer> list=null
            ;
    public pageadapter(Context context) {
        this.context=context;
    }

    //初始化
    @Override
    public Object instantiateItem( ViewGroup container, int position) {
        ImageView imageview=new ImageView(context);
        int a=position%list.size();
        imageview.setBackgroundResource(list.get(a));
        container.addView(imageview);
        return imageview;
    }

    @Override
    public void destroyItem( ViewGroup container, int position,  Object object) {
        container.removeView((View) object);
    }

    @Override
    public int getCount() {
        if(list!=null){
            return Integer.MAX_VALUE;
        }else {
            return 0;
        }
    }

    @Override
    public boolean isViewFromObject(@NonNull  View view, @NonNull  Object object) {
        return view==object;
    }

    public void setList(List<Integer> list) {
        this.list = list;
    }
}
